package com.baiku.sanhos.controller;

import com.baiku.sanhos.mapper.AppointMapper;
import com.baiku.sanhos.mapper.SourceMapper;
import com.baiku.sanhos.pojo.dto.AppointDTO;
import com.baiku.sanhos.pojo.dto.SourceDTO;
import com.baiku.sanhos.pojo.entity.Appoint;
import com.baiku.sanhos.pojo.vo.SourceVo;
import com.baiku.sanhos.response.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
@Api(tags = "号源管理")
@RequestMapping("/pa/source")
public class SourceController {

    @Autowired
    private SourceMapper sourceMapper;
    @Autowired
    private AppointMapper appointMapper;

    @ApiOperation("根据id查询排班信息")
    @GetMapping("/selectByAppointId")
    public ResultVO selectByAppointId(@RequestParam("id") Integer id){
       /* int count = appointMapper.selectSourceTotal(id);*/
        List<SourceVo> list = sourceMapper.selectByAppointId(id);
        if(list.size()==0){
            List<SourceVo> voList = sourceMapper.selectTotal(id);
            return ResultVO.ok(voList);
        }
        return ResultVO.ok(list);
    }
    @ApiOperation("根据id查询排班信息")
    @GetMapping("/selectAppoint")
    public ResultVO selectAppoint(@RequestParam("id") Integer id){
        List<SourceVo> list = sourceMapper.selectAppoint(id);
        return ResultVO.ok(list);
    }

    @PostMapping("/addSource")
    public ResultVO addSource(@RequestBody SourceDTO sourceDTO){
        Appoint appoint = appointMapper.queryByAppointFindDoctorNo(sourceDTO.getAppointId());
        sourceDTO.setSourceSurplus(sourceDTO.getSourceTotal());
        sourceDTO.setDoctorNo(appoint.getDoctorNo());
        sourceMapper.addSource(sourceDTO);
        return ResultVO.ok();
    }


}
